package com.yayan.xh.service;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yayan.xh.bean.ReviewBean;
import com.yayan.xh.dao.IReviewDao;
import com.yayan.xh.dao.ReviewDao;

@Service
public class ReviewService implements IReviewService {
	
	private IReviewDao reviewDao;
	
	public ReviewService() {
		reviewDao = new ReviewDao();
	}

	@Override
	public List<Map<String, Object>> getReviewPage(Map<String, String> map) {
		List<Map<String, Object>> result = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				if(null != map.get("rId")) {
					result = reviewDao.getReviewById(map);
				} else {
					result = reviewDao.getReviewPage(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public Integer getReviewPageCount(Map<String, String> map) {
		Integer count = 0;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				count = reviewDao.getReviewPageCount(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}

	@Override
	public ReviewBean getReviewByMatchId(Map<String, String> map) {
		ReviewBean bean = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId")) 
					&& null != map.get("matchId") && !"0".equalsIgnoreCase(map.get("matchId"))) {
				bean = reviewDao.getReviewByMatchId(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bean;
	}

	@Override
	public boolean saveReview(Map<String, String> map) {
		boolean f = false;
		try {
			ReviewBean bean = reviewDao.getReviewByMatchId(map);
			if(null != bean) {
				f = reviewDao.modifyReview(map);
			} else {
				f = reviewDao.saveReview(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

	@Override
	public List<ReviewBean> getReviewBack(Map<String, String> map) {
		List<ReviewBean> result = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				result = reviewDao.getReviewBack(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
